<% content_for :left_sidebar do  %>
  <%= render :partial => "layouts/sidebar/xiwenguanli" %>
<% end %>

<%- model_class = Report -%>
<div class="page-header">
  <h1>讲座报告 - 列表</h1>
</div>

<%= form_tag admins_reports_path,:method => :get do %>
    <table class="search_table">
      <tr>
        <td>稿件类型:
        	 <% if (current_user.admin? )  %>
        	   <%= select_tag :report_type,options_for_select([['我的稿件',1],['平台稿件',2]],session[:report_type]) %>
        	   <% else %>
        	    <%= select_tag :report_type,options_for_select([['我的稿件',1]],session[:report_type]) %>
        	 <% end %>
        
        </td>
        <td>稿件状态:
          <%= select_tag :check,options_for_select([['--请选择--',nil]] + Report::CHECK.to_a,params[:check]) %>
        </td>
      </tr>
      
      
       <tr>
      		<td>来稿单位:
        	  <%= select_tag(:department, options_from_collection_for_select(@departments, "name", "name"), prompt: '请选择')   %>
        	</td>
        	<td>
        	  发布时间:
        <%= text_field_tag :news_begin,session[:news_begin],:class => 'datepicker' %>~
        <%= text_field_tag :news_end,session[:news_end],:class => 'datepicker' %>
        
        <script type="text/javascript">
          $(document).ready(function(){
            $('.datepicker').datepicker({
                format: 'yyyy-mm-dd'
            });
          });
        </script>
          ID:
          <%= text_field_tag :report_id,session[:report_id] %>
        </td>
        	
        	
        	</tr>
        	
        	
      <tr>
        <td colspan="6">
          <%= select_button %>
          <%= new_button url: new_admins_report_path %>
        </td>
      </tr>
    </table>
<% end %>

<table class="table table-striped">
  <thead>
    <tr>
      <th>ID</th>
      <th>报告题目</th>
      <th>报告人</th>
       <th>新增时间</th>
      <th>时间</th>
      <th>发布人</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
    <% @reports.each do |report| %>
      <tr>
        <td><%= link_to report.id, admins_report_path(report) %></td>
        <td><%=link_to truncate(report.title,:length => 20),report_path(report),:target => '_blank' %></td>
        <td><%= truncate(report.reporter,:length => 20) %></td>
        
        <td><% if report.pubtime.nil?  %><%= report.created_at.strftime("%Y-%m-%d") rescue nil %> <% else %><%= report.pubtime.strftime("%Y-%m-%d") rescue nil %><%end%></td>
        
        <td><%= report.time.strftime("%Y-%m-%d %H:%M") %></td>
        <td><%= report.postby %></td>
        <td>
          <% if report.check == 0 %>
              <%= report.check_text %>
          <% else  %>
              <%= link_to "#{report.check_text}",admins_report_path(report) %>
          <% end %>
        </td>
        <td>
          <% if Report.can_edit?(report,@current_user) %>
              <%= link_to "编辑",edit_admins_report_path(report),:class => 'btn btn-default btn-xs' %>
              <%= link_to "删除",admins_report_path(report),
                          :method => :delete,
                          :data => { :confirm => '确定删除?' },
                          :class => 'btn btn-xs btn-danger' %>
          <% end %>
          <% if Report.can_approve?(report,@current_user) %>
              <%= link_to "审核",admins_report_path(report),:class => 'btn btn-info btn-xs' %>
          <% end %>
          <% if report.check == 0 %>
              <%= link_to "送审",admins_report_path(report),:class => 'btn btn-info btn-xs' %>
          <% end %>
          
          
          
             <%if current_user.admin? %>
                <%=link_to '修改发布时间',"javascript:void(0)",onclick:'change_time(this)' %>
          <%end %>
          <div class="change_time" style="display:none;position: absolute;
                  margin-top: -100px;
                  margin-left: 80px;
                  border: 1px solid gray;
                  padding: 5px;
                  background: white;" >

            <%= form_for(:report,url:change_time_admins_report_path(report), method:'post') do%>
                <span>输入新时间<input  type="text" name="new_time"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly/></span><br/>
                <input type="button"  name="btn" onclick="submit_it(this)" value="修改" />
            <% end %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<div class="count">
  <%= paginate @reports %>
</div>


<script src="/My97DatePicker/WdatePicker.js"></script>
<script>

function submit_it(obj){
   var name =$(obj).parent().find("input[name=new_time]").val();
       $(obj).parent().submit();
}
  function change_time(obj){
      var ct =$(obj).parent().find(".change_time");

      if(ct.css('display')=='none'){
          $(".change_time").hide();
          ct.show();
      }else
      {
          ct.hide();
      }

  }
</script>